﻿using RocksDbSharp;
using System;
using System.Collections.Generic;
using System.Text;

namespace JustMathCore.RocksDB
{
    public class DB : IDisposable
    {
        RocksDbSharp.RocksDb db;
        WriteBatch wb = null;
        public void Open(string path, bool create)
        {

            RocksDbSharp.DbOptions op = new RocksDbSharp.DbOptions();

            if (create)
                op = op.SetCreateIfMissing(true);

            op.SetCompression(Compression.No);
            if (System.IO.Directory.Exists(path) == false)
                System.IO.Directory.CreateDirectory(path);
            db = RocksDbSharp.RocksDb.Open(op, path);

        }
        public void Dispose()
        {
            db.Dispose();
        }
        public WriteBatch CreateWriteBatch()
        {
            var wb = new WriteBatch();
            return wb;
        }
        public void Write(WriteBatch wb)
        {
            db.Write(wb);
        }
        public void Apply()
        {

        }
        public byte[] Get(byte[] key)
        {
            return db.Get(key);
        }
    }
}
